package com.wxzz.elearing.course.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.course.entity.CurriculumSection;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

/**
 * <p>
 * 课程章节 Mapper 接口
 * </p>
 *
 * @author
 * @since 2021-03-10
 */
public interface CurriculumSectionMapper extends BaseMapper<CurriculumSection> {

    /**
     * 根据课程id查询章节列表 并排序
     * @param curriculumId
     * @return
     */
    @Select("SELECT\n" +
            "\t* \n" +
            "FROM\n" +
            "\t`curriculum_section` cs\n" +
            "\tJOIN curriculum_unit cu ON cs.curriculum_unit_id = cu.id \n" +
            "WHERE\n" +
            "\tcs.curriculum_id = #{curriculumId} AND cs.deleted = 0 AND cu.deleted = 0 \n" +
            "ORDER BY\n" +
            "\tcu.curriculum_unit_sort,\n" +
            "\tcs.curriculum_section_sort ASC ")
    List<CurriculumSection> listCurriculumSectionByCurriculumId(@Param("curriculumId")Long curriculumId);
}
